<?php
/**
 *
 * User: Richard
 * Date: 2020/3/14
 * Time: 14:56
 */

namespace Common\Controller;


use Think\Controller;

class DemoBaseController extends Controller
{
    public function __construct()
    {
        parent::__construct();
        //角色权限判断
        //如果为DEMO模块且不为登录方法 判断用户权限
        if (MODULE_NAME == 'Demo' && CONTROLLER_NAME != 'Login') {
            $adminId = session('admin_id');
            if (empty($adminId)) {
                //  todo 未登录前往登录页面
            }
            $roleId = session('role_id');
            $uId = M('role_menu u')
                ->join('left join __MENU__ m on m.id=u.menu_id')
                ->where([
                    'u.role_id' => $roleId,
                    'u.status' => 1,
                    'm.app' => MODULE_NAME,
                    'm.controller' => CONTROLLER_NAME,
                    'm.action' => ACTION_NAME,
                    'm.status' => 1,
                ])->field('u.id')->find();
            if (!$uId) {
                $this->returnerror('', '没有权限');
            }
        }

    }

    /**
     * 分页
     * @param int $total_size
     * @param int $page_size
     * @param int $current_page
     * @param int $listRows
     * @param string $pageParam
     * @param string $pageLink
     * @param bool $static
     * @return \Page
     */
    protected function page($total_size = 1, $page_size = 0, $current_page = 1, $listRows = 6, $pageParam = '', $pageLink = '', $static = false)
    {
        if ($page_size == 0) {
            $page_size = C("PAGE_LISTROWS");
        }

        if (empty($pageParam)) {
            $pageParam = C("VAR_PAGE");
        }

        $page = new \Page($total_size, $page_size, $current_page, $listRows, $pageParam, $pageLink, $static);
        $page->SetPager('Admin', '{first}{prev}&nbsp;{liststart}{list}&nbsp;{next}{last}<span>共{recordcount}条数据</span>', array("listlong" => "4", "first" => "首页", "last" => "尾页", "prev" => "上一页", "next" => "下一页", "list" => "*", "disabledclass" => ""));
        return $page;
    }
}